<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>vue.directive</title>
    <script type="text/javascript" src="../assests/js/vue.js"></script>
</head>
<body>
    <h1>vue.directive 自定义指令</h1>
    <hr>
    <div id="app">
        <p v-lzm="color">{{ num }}</p>
        <button @click="add">ADD</button>
        <button onclick="unbind()">destory</button>
    </div>
    <script>
        // Vue.directive("lzm",function(el,binding){
        //     console.log(el);
        //     console.log(binding);
        //     el.style.color = binding.value;
        // });
            
        Vue.directive("lzm",{
           bind:function(el,binding){
               console.log("1----bind");
               el.style.color = binding.value;
           },
           inserted:function(){
               console.log("2----inserted");
           },
           update:function(){
               console.log("3----update");
           },
           componentUpdated:function(){
               console.log("4----componentUpdated");
           },
           unbind:function(){
               console.log("5----unbind");
           }
        });
        function unbind(){
            app.$destroy();
        }
        var app = new Vue({
            el:"#app",
            data:{
                num:10,
                color:"blue"
            },
            methods:{
                add:function(){
                    this.num++;
                }
            }
        });
    </script>
</body>
</html>